package com.hs.health.cloud.tars.controller.testhttp;

import com.hs.health.cloud.tars.bean.facecommon.CommonIn;
import com.hs.health.cloud.tars.bean.facecommon.CommonOut;
import com.hs.health.cloud.tars.bean.faceidapi.AuthIdCardReq;
import com.hs.health.cloud.tars.bean.faceidapi.AuthIdCardRsp;
import com.hs.health.cloud.tars.controller.testhttp.prx.FaceAuthPrx;
import com.hs.health.cloud.tars.controller.testhttp.prx.FaceAuthPrxCallback;
import com.hs.health.cloud.tars.utils.LogUtils;
import com.qq.tars.client.CommunicatorFactory;
import com.qq.tars.common.support.Holder;
import com.qq.tars.spring.annotation.TarsHttpService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 描述:
 * 身份认证
 *
 * @outhor Administrator
 * @create 2019-04-19 8:51
 */
@TarsHttpService("HttpObj")
@RestController
public class HelloServantImpl implements HelloServant {

//    @TarsClient("HealthCloud.TenCloudApiServier.FaceAuthObj")
//    FaceAuthPrx prx;

    @RequestMapping(path = "/test")
    @Override
    public String hello() {
        LogUtils.info("Haojg is testing");
        return "aaaaaaaa";
    }

    /**
     * 请求服务端例子
     */
    @RequestMapping(path = "/idAuth")
    @Override
    public String faceIdAuth() {

        LogUtils.info("Haojg faceIdAuth:");
        FaceAuthPrx proxy = CommunicatorFactory.getInstance().getCommunicator()
                .stringToProxy(FaceAuthPrx.class, "HealthCloud.TenCloudApiServier.FaceAuthObj");
        //同步调用
        AuthIdCardReq req = new AuthIdCardReq("郝建国", "13072219851102113X");
        Holder<AuthIdCardRsp> rsp = new Holder<>();
        CommonIn commonIn = new CommonIn();
        Holder<CommonOut> commonOut = new Holder<>();
        CommonOut t_commonOut = new CommonOut();
        commonOut.setValue(t_commonOut);
        LogUtils.info("llllllll");
        // 回调函数
        FaceAuthPrxCallback callback = new FaceAuthPrxCallback() {
            @Override
            public void callback_AuthIdCard(String ret) {

            }
            @Override
            public void callback_exception(Throwable ex) {
                ex.printStackTrace();
            }
            @Override
            public void callback_expired() {
            }
        };
        proxy.async_AuthIdCard(new FaceAuthPrxCallback() {
            @Override
            public void callback_AuthIdCard(String ret) {
                System.out.println(ret);
            }
        }, req, rsp, commonIn, commonOut);
//        faceAuthService.test();
        LogUtils.info("request result finish");
        return "kkkkkkk";
    }

}
